package com.xugui.learn.pay.pojo.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * 支付渠道枚举类
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum PayChannel {

    WECHAT_PAY("wechat", "微信支付"),
    ALI_PAY("alipay", "支付宝"),
    UNION_PAY("union", "银联支付");

    private String code;

    private String name;

    /**
     * 根据 code 获取支付渠道的枚举类
     *
     * @param code 支付渠道的 code
     * @return 支付渠道的枚举类
     */
    public static PayChannel getByCode(String code) {
        for (PayChannel item : values()) {
            if (item.getCode().equals(code)) {
                return item;
            }
        }
        return null;
    }
}